package com.yjs.ppjokedemo.ui;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.yjs.ppjokedemo.R;
import com.yjs.ppjokedemo.adapter.VideoListAdapter;
import com.yjs.ppjokedemo.bean.VideoProduct;
import com.yjs.ppjokedemo.databinding.FragmentHomeBinding;
import com.yjs.ppjokedemo.viewmodel.VideoViewModel;

import java.util.List;

/**
 * 首页视频播放
 * */
public class HomeFragment extends Fragment  {

    FragmentHomeBinding mFragmentHomeBinding;
    private VideoViewModel mVideoViewModel;
    private VideoListAdapter mVideoListAdapter;

    public HomeFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        mFragmentHomeBinding = FragmentHomeBinding.inflate(inflater,container,false);
        return mFragmentHomeBinding.getRoot();
    }

//    @Override
//    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
//        super.onViewCreated(view, savedInstanceState);
//
//        //给RecyclerView设置布局样式
//        mFragmentHomeBinding.rvHome.setLayoutManager(new LinearLayoutManager(getContext()));
//        //设置适配器
//        mVideoListAdapter = new VideoListAdapter( this);
//        mFragmentHomeBinding.rvHome.setAdapter(mVideoListAdapter);
//
//        mVideoViewModel = new ViewModelProvider(requireActivity()).get(VideoViewModel.class);
//        //通过ViewModel获取到Repo数据源的方法进行解析
//        mVideoViewModel.getProducts().observe(getViewLifecycleOwner(), new Observer<List<VideoProduct>>() {
//            @Override
//            public void onChanged(List<VideoProduct> videoProducts) {
//                //给Adapter赋值,传递List数据源
//                mVideoListAdapter.submitList(videoProducts);
//            }
//        });


}